#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.10.0
 Author:         Yegor Chemisov

 Script Function:
	Prepare esperanto text to Palm devices.

#ce ----------------------------------------------------------------------------


#include <File.au3>

CodesToCx(@ScriptDir & '\00.html')

Func ReplaceInFile($io_file, $io_word, $io_replacement)
    Dim $Records
    $Lines = _FileCountLines($io_File)
    If Not _FileReadToArray($io_file, $Records) Then
        ConsoleWriteError("There was an error reading > " & $io_file & @CRLF)
        Exit
    ElseIf _FileReadToArray($io_file, $Records) == "" Then
        ConsoleWriteError("File was found to be blank!" & @CRLF)
    ElseIf Not @error Then
        ConsoleWrite("> File was all good!" & @CRLF)
    EndIf
    $File = FileOpen($io_file, 2)
   ; DEBUG = ConsoleWrite("+> Found: " & $Lines & " lines!" & @CRLF)
    For $ax = 1 To $Records[0]
        ConsoleWrite("+> " & $Records[$ax] & @CRLF)
        $Replace = StringReplace($Records[$ax], $io_word, $io_replacement)
        ConsoleWrite("+> " & $Replace & @CRLF)

		FileWrite($File, $Replace & @CRLF)
        If Not @error Then
            ConsoleWrite("> Replaced String!" & @CRLF)
        Else
            ConsoleWriteError("Error replacing text!" & @CRLF)
        EndIf
    Next
    FileClose($File)
EndFunc

Func CodesToCx($io_file)
    Dim $Records
    $Lines = _FileCountLines($io_File)
    If Not _FileReadToArray($io_file, $Records) Then
        ConsoleWriteError("There was an error reading > " & $io_file & @CRLF)
        Exit
    ElseIf _FileReadToArray($io_file, $Records) == "" Then
        ConsoleWriteError("File was found to be blank!" & @CRLF)
    ElseIf Not @error Then
        ConsoleWrite("> File was all good!" & @CRLF)
    EndIf
    $File = FileOpen($io_file, 2)

For $ax = 1 To $Records[0]
		
		$Replace = $Records[$ax]
        $Replace = StringReplace($Replace, "&#264;", "Cx")
        $Replace = StringReplace($Replace, "&#265;", "cx")
        $Replace = StringReplace($Replace, "&#284;", "Gx")
        $Replace = StringReplace($Replace, "&#285;", "gx")
        $Replace = StringReplace($Replace, "&#292;", "Hx")
        $Replace = StringReplace($Replace, "&#293;", "hx")
        $Replace = StringReplace($Replace, "&#308;", "Jx")
        $Replace = StringReplace($Replace, "&#309;", "jx")
        $Replace = StringReplace($Replace, "&#348;", "Sx")
        $Replace = StringReplace($Replace, "&#349;", "sx")
        $Replace = StringReplace($Replace, "&#364;", "Ux")
        $Replace = StringReplace($Replace, "&#365;", "ux")

		FileWrite($File, $Replace & @CRLF)
        If Not @error Then
            ConsoleWrite("> Replaced String!" & @CRLF)
        Else
            ConsoleWriteError("Error replacing text!" & @CRLF)
        EndIf
    Next
    FileClose($File)
EndFunc
